package com.yzd.learnjava.arrays;

import java.util.Arrays;

import com.yzd.learnjava.util.ConvertTo;
import com.yzd.learnjava.util.Generated;
import com.yzd.learnjava.util.Generator;
import com.yzd.learnjava.util.Print;
import com.yzd.learnjava.util.RandomGenerator;

public class ArraySearching {
	public static void main(String[] args) {
		Generator<Integer> gen = new RandomGenerator.Integer(1000);
		int[] a = ConvertTo.primitive(Generated.array(new Integer[25], gen));
		Arrays.sort(a);
		Print.print("Sorted array : " + Arrays.toString(a));
		while(true) {
			int r = gen.next();
			int location = Arrays.binarySearch(a, r);
			if(location > 0) {
				Print.print("Location of " + r + " is " + location + ", a[" + location + "] = " + a[location]);
				break;
			}
		}
		
	}
}
